<template>
  <div class="w">
    <div class="header">
      <i class="iconfont icon-fanhui" @click="back"></i>
      <span class="title">我的收货地址</span>
    </div>
    <div class="info">
      <div class="info_list">
        <div class="list_card" v-for="(item, index) in addressList" :key="index">
          <div class="card_left">
            <div class="card_left_title">
              <span>{{ item.address }}</span>
              <div class="icon" v-if="item.isDefault == 1">
                <span>默认</span>
              </div>
            </div>
            <div class="card_left_info">
              <span>{{ item.people }}</span>
              <span class="span" v-if="item.sex == 0">先生</span>
              <span class="span" v-if="item.sex == 1">女士</span>
              <span>{{ item.phone }}</span>
            </div>
          </div>
          <div class="card_right" @click="goNext(item)">
            <i class="iconfont icon-bianji"></i>
          </div>
        </div>
      </div>
      <div class="button">
        <el-button @click="goNext('add')">添加收货地址</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      info: [],
      addressList: [],
    };
  },

  created() {
    this.info = JSON.parse(window.localStorage.getItem('userInfo'));
    this.getAddressList();
  },

  methods: {
    back() {
      this.$router.push('my');
    },
    goNext(url) {
      if (url == 'add') {
        this.$router.push('/addAddress');
      } else {
        this.$router.push({ path: '/addAddress', query: { addressInfo: url } });
      }
    },
    async getAddressList() {
      const { data: res } = await this.$http.get('addressBook/getAddressBookList/' + this.info.id);
      if (res.code == 1) {
        this.addressList = res.data;
      } else {
        return this.$message.error('信息获取失败');
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.w {
  height: 100vh;
  width: 100%;
  background-color: #fff;
  .header {
    height: 50px;
    color: #0a0a0a;
    text-align: center;
    position: relative;
    .icon-fanhui {
      position: absolute;
      font-size: 25px;
      line-height: 50px;
      left: 10px;
    }
    .title {
      font-size: 20px;
      letter-spacing: 1px;
      line-height: 50px;
    }
  }
  .info {
    position: relative;
    height: calc(100vh - 100px);
    padding: 15px;
    .info_list {
      height: auto;
      margin-top: 10px;
      .list_card {
        border-bottom: 2px solid #f4f4f4;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 15px;
        .card_left {
          .card_left_title {
            font-size: 20px;
            font-weight: bold;
            color: #393939;
            letter-spacing: 1px;
            margin-bottom: 8px;
            display: flex;
            .icon {
              border: 1px solid #ffc200;
              border-radius: 5px;
              width: 35px;
              text-align: center;
              padding: 2px 0px;
              font-size: 13px;
              color: #ffc200;
              line-height: 16px;
              height: 15px;
              margin-left: 5px;
            }
          }
          .card_left_info {
            color: #a2a2a2;
            font-size: 15px;
            margin-bottom: 10px;
            .span {
              margin-left: 15px;
              margin-right: 40px;
            }
          }
        }
        .card_right {
          .icon-bianji {
            font-size: 18px;
            color: #979797;
          }
        }
      }
    }
    .button {
      :deep(.el-button) {
        position: absolute;
        bottom: 0;
        background-color: #ffc200;
        height: 50px;
        width: 360px;
        border-radius: 50px;
        font-size: 16px;
      }
    }
  }
}
</style>